#include <iostream>
#include <memory>
using namespace std;

struct FILECloser{
    void operator()(FILE * fp){
        if (fp){
            fclose(fp);
            cout << "file close" << endl;
        }
    }
};
template<class T>
struct FILECloser{
    void operator()(T * fp){
        if (fp){
            fclose(fp);
            cout << "file close" << endl;
        }
    }
};

void test0(){
    // unique_ptr<FILE, FILECloser<FILE>> up(fopen("hello.txt", "a+"));
    const string msg = "hello, world!\n";
    // fwrite(msg.c_str(), 1, msg.size(), up.get());

    FILECloser fc;
    shared_ptr<FILE> sp(fopen("sp.txt", "a+"), fc);
    fwrite(msg.c_str(), 1, msg.size(), sp.get());
}

int main(){
    test0();

    return 0;
}